From: Ewan Mellor Date: Wed, 27 Dec 2006 15:39:04 +0000 (+0000) Subject: Override logging.Logger.findCaller so that the trace function here does not X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~15422^2~148 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22?a=commitdiff_plain;h=85a87721a75da96264736d90852a7fc0ae3dec7e;p=xen.git Override logging.Logger.findCaller so that the trace function here does not appear as the source of log messages. Remove the logger name from the log format -- it's adding no useful information. Signed-off-by: Ewan Mellor --- diff --git a/tools/python/xen/xend/XendLogging.py b/tools/python/xen/xend/XendLogging.py index 32cd13c5db..e889449fd0 100644 --- a/tools/python/xen/xend/XendLogging.py +++ b/tools/python/xen/xend/XendLogging.py @@ -16,7 +16,10 @@ # Copyright (C) 2005, 2006 XenSource Ltd. #============================================================================ +import inspect import os +import os.path +import sys import stat import tempfile import types @@ -38,6 +41,24 @@ if 'TRACE' not in logging.__dict__: self.log(logging.TRACE, *args, **kwargs) logging.Logger.trace = trace + def findCaller(self): + """ + Override logging.Logger.findCaller so that the above trace function + does not appear as the source of log messages. The signature of this + function changed between Python 2.3 and 2.4. + """ + frames = inspect.stack() + thisfile = os.path.normcase(frames[0][1]) + for frame in frames: + filename = os.path.normcase(frame[1]) + if filename != thisfile and filename != logging._srcfile: + major, minor, _, _, _ = sys.version_info + if major == 2 and minor >= 4: + return filename, frame[2], frame[3] + else: + return filename, frame[2] + logging.Logger.findCaller = findCaller + log = logging.getLogger("xend") @@ -46,7 +67,7 @@ MAX_BYTES = 1 << 20 # 1MB BACKUP_COUNT = 5 STDERR_FORMAT = "[%(name)s] %(levelname)s (%(module)s:%(lineno)d) %(message)s" -LOGFILE_FORMAT = "[%(asctime)s %(name)s %(process)d] %(levelname)s (%(module)s:%(lineno)d) %(message)s" +LOGFILE_FORMAT = "[%(asctime)s %(process)d] %(levelname)s (%(module)s:%(lineno)d) %(message)s" DATE_FORMAT = "%Y-%m-%d %H:%M:%S"